import React, { useState, useContext, useEffect } from "react";
import { store } from "../../../store/index";
// import Geolocation from "Geolocation";
import {
  View,
  Text,
  StyleSheet,
  TouchableOpacity,
  ScrollView,
  TextInput,
  ActivityIndicator,
  TouchableWithoutFeedback,
  Alert,
  Modal,
} from "react-native";

import userQuesContext from "../../../context/questionnaire/UserQuesContext";
import MyQuesContext from "../../../context/questionnaire/MyQuesContext";

import ShowChoiceQues from "../../../components/showSubject/showChoiceQues";
import ShowEssayQues from "../../../components/showSubject/ShowEssayQues";
import ShowCompletion from "../../../components/showSubject/ShowCompletion";
import ShowComplexQues from "../../../components/showSubject/ShowComplexQues";

import { Ionicons } from "@expo/vector-icons";
import { MaterialIcons } from "@expo/vector-icons";

const Loading = ({ text }) => {
  return (
    <View style={styles.alterView}>
      <ActivityIndicator animating={true} size={"large"} color="#ddd" />
      <Text style={{ color: "#ccc", marginTop: 10 }}>{text}</Text>
    </View>
  );
};

const Error = () => {
  return (
    <View style={styles.alterView}>
      <Text style={{ color: "#ccc", marginTop: 10 }}>出错了...</Text>
    </View>
  );
};

const CompleteQues = ({ navigation, route, navigator }) => {
  const { opinions, quesIndex, isEdit, isAdd, btnType, examine } = route.params;
  const { useQuesLoading, UserQuesData, setLoading, newQues } =
    useContext(userQuesContext);
  const {
    MyQuesData,
    addNewQues,
    editMyQues,
    postMyQues,
    editAndJudgeMyQues,
    errorAlter,
    conditionAlter,
  } = useContext(MyQuesContext);
  const [isVisible, setIsVisible] = useState(false);
  const [haveSave, setHaveSave] = useState(true);
  const [isAddTag, setIsAddTag] = useState(isAdd);

  React.useLayoutEffect(() => {
    if (btnType != 1) {
      navigation.setOptions({
        // title: "修改题目组",
        headerRight: () => (
          <View style={{ flexDirection: "row" }}>
            <TouchableOpacity
              onPress={() => {
                navigation.navigate("入户资料", {
                  filedata: UserQuesData.filedata,
                });
              }}
            >
              <Ionicons
                name="file-tray-full-sharp"
                size={20}
                color="#fff"
                style={{ marginRight: 10 }}
              />
            </TouchableOpacity>
            <TouchableOpacity
              onPress={() => {
                navigation.navigate("问题清单", {
                  myQuesIndex: quesIndex,
                  flag: "show",
                  showProData: UserQuesData.userproblem,
                });
              }}
            >
              <MaterialIcons
                name="report-problem"
                size={20}
                color="#fff"
                style={{ marginRight: 5 }}
              />
            </TouchableOpacity>
          </View>
        ),
      });
    }
    if (!isAddTag && !isEdit) {
      // console.log("意见反馈");
      navigation.setOptions({
        title: "问卷审核",
      });
    }
    if (btnType != 1 && btnType != 2) {
      // console.log("意见反馈");
      navigation.setOptions({
        title: "问卷查看",
      });
    }
  }, [navigation]);

  const [allSkipArr, setAllSkipArr] = useState([]);
  let skipObj = [];

  let t_body = JSON.parse(JSON.stringify(UserQuesData.body));
  const [QuesBody, setQuesBody] = useState(
    JSON.parse(JSON.stringify(UserQuesData.body))
  );
  const [title, setTitle] = useState(UserQuesData.title);
  // 每个题目组是否展开，默认展开
  const [visibleArr, setVisibleArr] = useState([]);
  useEffect(async () => {
    let t_Arr = [];
    if (isAddTag) {
      for (let i = 0; i < UserQuesData.body.length; i++) {
        t_Arr.push(false);
        // console.log("---", visibleArr);
        skipObj.push([]);
        for (let j = 0; j < UserQuesData.body[i].contents.length; j++) {
          skipObj[i].push([]);
          if (UserQuesData.body[i].contents[j].type == 5) {
            for (
              let k = 0;
              k < UserQuesData.body[i].contents[j].title.length;
              k++
            ) {
              skipObj[i][j].push([]);
            }
          }
        }
      }
    } else {
      for (let i = 0; i < UserQuesData.body.length; i++) {
        t_Arr.push(false);
        // console.log("---", visibleArr);
        skipObj.push([]);
        for (let j = 0; j < UserQuesData.body[i].contents.length; j++) {
          skipObj[i].push([]);
          if (UserQuesData.body[i].contents[j].type == 5) {
            for (
              let k = 0;
              k < UserQuesData.body[i].contents[j].title.length;
              k++
            ) {
              skipObj[i][j].push([]);
              if (
                UserQuesData.body[i].contents[j].title[k].skipType != 0 &&
                UserQuesData.body[i].contents[j].title[k].type != -1
              ) {
                for (
                  let p = 0;
                  p <
                  UserQuesData.body[i].contents[j].title[k].skipDetail.length;
                  p++
                ) {
                  let isSkipValue;
                  isSkipValue = await isSkip(
                    UserQuesData.body[i].contents[j].title[k].skipType,
                    UserQuesData.body[i].contents[j].title[k].type,
                    UserQuesData.body[i].contents[j].title[k].answer,
                    UserQuesData.body[i].contents[j].title[k].skipDetail[p],
                    UserQuesData.body[i].contents[j].title[k].relation,
                    [i, j, k]
                  );
                  console.log("是否跳过---", isSkipValue);
                  // handleSkip(!isSkipValue, value.title[key3].skipDetail[i].skipNumber);
                  if (isSkipValue) {
                    skipObj[i][j][k] = JSON.parse(
                      JSON.stringify(
                        UserQuesData.body[i].contents[j].title[k].skipDetail[p]
                          .skipNumber
                      )
                    );
                  } else {
                    skipObj[i][j][k] = [];
                  }
                }
              }
            }
          } else {
            if (
              UserQuesData.body[i].contents[j].skipType != 0 &&
              UserQuesData.body[i].contents[j].type != -1
            ) {
              let temp,
                flag = false;
              for (
                let p = 0;
                p < UserQuesData.body[i].contents[j].skipDetail.length;
                p++
              ) {
                let isSkipValue;
                isSkipValue = await isSkip(
                  UserQuesData.body[i].contents[j].skipType,
                  UserQuesData.body[i].contents[j].type,
                  UserQuesData.body[i].contents[j].answer,
                  UserQuesData.body[i].contents[j].skipDetail[p],
                  UserQuesData.body[i].contents[j].relation,
                  [i, j]
                );
                console.log("是否跳过---", isSkipValue);
                if (isSkipValue) {
                  flag = true;
                  temp =
                    UserQuesData.body[i].contents[j].skipDetail[p].skipNumber;
                } else {
                  skipObj[i][j] = [];
                }
              }
              if (flag) skipObj[i][j] = JSON.parse(JSON.stringify(temp));
              flag = false;
            }
          }
        }
      }
    }
    // console.log("初始化---", skipObj);
    setAllSkipArr(JSON.parse(JSON.stringify(skipObj)));
    setVisibleArr(JSON.parse(JSON.stringify(t_Arr)));
  }, []);

  // 跳过题目
  const handleSkip = async (t_visible, skipArr) => {
    setHaveSave(false);
    console.log("开始跳过---");
    for (let i = 0; i < skipArr.length; i++) {
      if (skipArr[i].length == 1) {
        let n1 = skipArr[i][0];
        // console.log("跳过前", n1, "---", t_body[n1].visible);
        t_body[n1].visible = t_visible;
        // console.log("跳过后", n1, "---", t_body[n1].visible);
      } else if (skipArr[i].length == 2) {
        let n1 = skipArr[i][0];
        let n2 = skipArr[i][1];
        // console.log("跳过前---", n1, n2, t_body[n1].contents[n2].visible);
        t_body[n1].contents[n2].visible = t_visible;
        // console.log("跳过后---", n1, n2, t_body[n1].contents[n2].visible);
      } else if (skipArr[i].length == 3) {
        let n1 = skipArr[i][0];
        let n2 = skipArr[i][1];
        let n3 = skipArr[i][2];
        // console.log(
        //   "跳过前---",
        //   n1,
        //   n2,
        //   n3,
        //   t_body[n1].contents[n2].title[n3].visible
        // );
        t_body[n1].contents[n2].title[n3].visible = t_visible;
        // console.log(
        //   "跳过后---",
        //   n1,
        //   n2,
        //   n3,
        //   t_body[n1].contents[n2].title[n3].visible
        // );
      }
    }
  };

  // 判断是否跳过
  const isSkip = (skipType, quesType, answer, skipDetail, relation, nowNum) => {
    let isSkipValue = false;
    // console.log("跳过类型---", skipType, "题目类型---", quesType);
    // console.log("答案---", answer, "，跳过条件---", skipDetail.condition);
    // console.log("关联题目---", relation);
    if (skipType == 1) {
      // 且跳过
      if (quesType == 7 || quesType == 2) {
        isSkipValue = answer == skipDetail.condition[0];
      } else if (quesType == 3) {
        isSkipValue = answer[skipDetail.condition[0]];
        for (let i = 1; i < skipDetail.condition.length; i++) {
          isSkipValue = isSkipValue && answer[skipDetail.condition[i]];
        }
      } else if (quesType == 1) {
        isSkipValue = answer == skipDetail.condition;
      }
    } else if (skipType == 2) {
      // 或跳过
      if (quesType == 2) {
        isSkipValue = answer == skipDetail.condition[0];
        for (let i = 1; i < skipDetail.condition.length; i++) {
          isSkipValue = isSkipValue || answer == skipDetail.condition[i];
        }
      } else if (quesType == 3) {
        isSkipValue = answer[skipDetail.condition[0]];
        for (let i = 1; i < skipDetail.condition.length; i++) {
          isSkipValue = isSkipValue || answer[skipDetail.condition[i]];
        }
      }
    } else if (skipType == 3) {
      // 否跳过
      if (quesType == 2) {
        isSkipValue = answer != skipDetail.condition[0];
      } else if (quesType == 3) {
        isSkipValue = !answer[skipDetail.condition[0]];
        console.log(isSkipValue);
      }
    } else if (skipType == 4) {
      // 特殊跳过
      console.log("特殊跳过", nowNum);
      isSkipValue = true;
      for (let i = 0; i < relation.length; i++) {
        let t_ques = QuesBody[relation[i][0]].contents[relation[i][1]];
        if (nowNum[0] == relation[i][0] && nowNum[1] == relation[i][1]) {
          isSkipValue =
            isSkipValue && t_ques.skipDetail[0].condition[0] == answer;
        } else {
          isSkipValue =
            isSkipValue && t_ques.skipDetail[0].condition[0] == t_ques.answer;
        }
      }
    } else if (skipType == 5 || skipType == 6) {
      let a_answer =
        relation[0].length == 2
          ? QuesBody[relation[0][0]].contents[relation[0][1]].answer
          : QuesBody[relation[0][0]].contents[relation[0][1]].title[
              relation[0][2]
            ].answer;
      if (answer != "" && typeof parseInt(answer) == "number") {
        if (
          a_answer != "" &&
          typeof a_answer != "undefined" &&
          typeof parseInt(a_answer) == "number"
        ) {
          if (skipType == 5 && parseInt(answer) <= parseInt(a_answer)) {
            isSkipValue = true;
            console.log("小于");
          } else if (skipType == 6 && parseInt(answer) >= parseInt(a_answer)) {
            isSkipValue = true;
            console.log("大于");
          }
        }
      }
    }
    return isSkipValue;
  };

  // 编辑答案
  const editAnswer = async (key1, key2, key3, value) => {
    skipObj = JSON.parse(JSON.stringify(allSkipArr));
    // console.log("现在---", skipObj);
    setHaveSave(false);
    t_body = QuesBody;
    if (t_body[key1].contents[key2].type != 5) {
      // 修改答案
      t_body[key1].contents[key2].optionFlag = value.optionFlag;
      t_body[key1].contents[key2].answer = value.answer;
      // 处理跳过
      let t_ques = t_body[key1].contents[key2];
      if (t_ques.skipType != 0) {
        if (t_ques.skipDetail.length == 1) {
          let isSkipValue;
          isSkipValue = await isSkip(
            t_ques.skipType,
            t_ques.type,
            value.answer,
            t_ques.skipDetail[0],
            t_ques.relation,
            [key1, key2]
          );
          if (isSkipValue) {
            if (t_ques.relation.length > 0) {
              for (let m = 0; m < t_ques.relation.length; m++) {
                if (t_ques.relation[m].length == 2) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]] =
                    JSON.parse(JSON.stringify(t_ques.skipDetail[0].skipNumber));
                } else if (t_ques.relation[m].length == 3) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]][
                    t_ques.relation[m][2]
                  ] = JSON.parse(
                    JSON.stringify(t_ques.skipDetail[0].skipNumber)
                  );
                }
              }
            }
            skipObj[key1][key2] = JSON.parse(
              JSON.stringify(t_ques.skipDetail[0].skipNumber)
            );
            console.log("跳过---", skipObj[key1][key2]);
          } else {
            if (t_ques.relation.length > 0) {
              for (let m = 0; m < t_ques.relation.length; m++) {
                if (t_ques.relation[m].length == 2) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]] = [];
                } else if (t_ques.relation[m].length == 3) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]][
                    t_ques.relation[m][2]
                  ] = [];
                }
              }
            }
            skipObj[key1][key2] = [];
          }
          // handleSkip(!isSkipValue, t_ques.skipDetail[0].skipNumber);
        } else {
          let temp,
            flag = false;
          for (let i = 0; i < t_ques.skipDetail.length; i++) {
            let isSkipValue;
            isSkipValue = await isSkip(
              t_ques.skipType,
              t_ques.type,
              value.answer,
              t_ques.skipDetail[i],
              t_ques.relation,
              [key1, key2]
            );
            console.log("是否跳过---", isSkipValue);
            if (isSkipValue) {
              flag = true;
              temp = t_ques.skipDetail[i].skipNumber;
            } else {
              if (t_ques.relation.length > 0) {
                for (let m = 0; m < t_ques.relation.length; m++) {
                  if (t_ques.relation[m].length == 2) {
                    skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]] = [];
                  } else if (t_ques.relation[m].length == 3) {
                    skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]][
                      t_ques.relation[m][2]
                    ] = [];
                  }
                }
              }
              skipObj[key1][key2] = [];
            }
          }
          if (flag) {
            if (t_ques.relation.length > 0) {
              for (let m = 0; m < t_ques.relation.length; m++) {
                if (t_ques.relation[m].length == 2) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]] =
                    JSON.parse(JSON.stringify(temp));
                } else if (t_ques.relation[m].length == 3) {
                  skipObj[t_ques.relation[m][0]][t_ques.relation[m][1]][
                    t_ques.relation[m][2]
                  ] = JSON.parse(JSON.stringify(temp));
                }
              }
            }
            skipObj[key1][key2] = JSON.parse(JSON.stringify(temp));
          }
          flag = false;
        }
      }
    } else if (t_body[key1].contents[key2].type == 5) {
      // 修改答案
      t_body[key1].contents[key2] = value;
      // 处理跳过
      console.log("复合题型");
      if (value.title[key3].skipType != 0) {
        // t_body = JSON.parse(JSON.stringify(QuesBody));
        for (let i = 0; i < value.title[key3].skipDetail.length; i++) {
          let isSkipValue;
          isSkipValue = await isSkip(
            value.title[key3].skipType,
            value.title[key3].type,
            value.title[key3].answer,
            value.title[key3].skipDetail[i],
            value.title[key3].relation,
            [key1, key2, key3]
          );
          console.log("是否跳过---", isSkipValue);
          // handleSkip(!isSkipValue, value.title[key3].skipDetail[i].skipNumber);
          if (isSkipValue) {
            if (value.title[key3].relation.length > 0) {
              for (let m = 0; m < value.title[key3].relation.length; m++) {
                if (value.title[key3].relation[m].length == 2) {
                  skipObj[value.title[key3].relation[m][0]][
                    value.title[key3].relation[m][1]
                  ] = JSON.parse(
                    JSON.stringify(value.title[key3].skipDetail[i].skipNumber)
                  );
                } else if (value.title[key3].relation[m].length == 3) {
                  skipObj[value.title[key3].relation[m][0]][
                    value.title[key3].relation[m][1]
                  ][value.title[key3].relation[m][2]] = JSON.parse(
                    JSON.stringify(value.title[key3].skipDetail[i].skipNumber)
                  );
                }
              }
            }
            skipObj[key1][key2][key3] = JSON.parse(
              JSON.stringify(value.title[key3].skipDetail[i].skipNumber)
            );
          } else {
            if (value.title[key3].relation.length > 0) {
              for (let m = 0; m < value.title[key3].relation.length; m++) {
                if (value.title[key3].relation[m].length == 2) {
                  skipObj[value.title[key3].relation[m][0]][
                    value.title[key3].relation[m][1]
                  ] = [];
                } else if (value.title[key3].relation[m].length == 3) {
                  skipObj[value.title[key3].relation[m][0]][
                    value.title[key3].relation[m][1]
                  ][value.title[key3].relation[m][2]] = [];
                }
              }
            }
            skipObj[key1][key2][key3] = [];
          }
        }
      }
    }
    setAllSkipArr(JSON.parse(JSON.stringify(skipObj)));
    for (let i = 0; i < QuesBody.length; i++) {
      t_body[i].visible = true;
      for (let j = 0; j < QuesBody[i].contents.length; j++) {
        if (
          QuesBody[i].contents[j].type != 5 &&
          QuesBody[i].contents[j].type != -1
        ) {
          t_body[i].contents[j].visible = true;
        } else if (
          QuesBody[i].contents[j].type == 5 &&
          QuesBody[i].contents[j].type != -1
        ) {
          t_body[i].contents[j].visible = true;
          for (let k = 0; k < QuesBody[i].contents[j].title.length; k++) {
            if (
              t_body[i].contents[j].title[k].type != 5 &&
              t_body[i].contents[j].title[k].type != -1
            ) {
              t_body[i].contents[j].title[k].visible = true;
            } else if (t_body[i].contents[j].title[k].type == -1) {
              t_body[i].contents[j].title[k].visible = false;
            }
          }
        } else if (QuesBody[i].contents[j].type == -1) {
          t_body[i].contents[j].visible = false;
        }
      }
    }
    console.log("A3的跳过---", skipObj[0][2]);
    for (let i = 0; i < QuesBody.length; i++) {
      for (let j = 0; j < QuesBody[i].contents.length; j++) {
        if (
          QuesBody[i].contents[j].type != 5 &&
          QuesBody[i].contents[j].type != -1
        ) {
          if (skipObj[i][j].length > 0) {
            handleSkip(false, skipObj[i][j]);
          }
        } else if (
          QuesBody[i].contents[j].type == 5 &&
          QuesBody[i].contents[j].type != -1
        ) {
          for (let k = 0; k < QuesBody[i].contents[j].title.length; k++) {
            if (skipObj[i][j][k].length > 0) {
              handleSkip(false, skipObj[i][j][k]);
            }
          }
        }
      }
    }
    setQuesBody(JSON.parse(JSON.stringify(t_body)));
  };

  const [isSaving, setIsSaving] = useState(false);
  const [isExamining, setIsExamining] = useState(false);

  const handleExamine = (quesIndex, state) => {
    let flag = state == 3 ? "驳回" : "通过";
    Alert.alert("", "确定" + flag + "这份问卷吗？", [
      {
        text: "取消",
      },
      {
        text: "确定",
        onPress: async () => {
          setIsExamining(true);
          let isSuccess = true;
          await examine(quesIndex, state, (value) => {
            isSuccess = value;
          });
          setIsExamining(false);
          if (isSuccess) {
            Alert.alert("处理成功");
          } else {
            Alert.alert("处理失败");
          }
          navigation.goBack();
        },
      },
    ]);
  };

  console.log(useQuesLoading);
  // setLoading("end");

  return (
    <View style={styles.container}>
      {useQuesLoading == "ing" ? (
        <Loading text="Loading..."></Loading>
      ) : (
        <View style={{ height: "100%" }}>
          {QuesBody.length == 0 ? (
            <View style={styles.alterView}>
              <Text style={{ color: "#ccc", marginTop: 10 }}>暂无问卷</Text>
            </View>
          ) : (
            <ScrollView>
              <View>
                <View
                  style={{
                    marginTop: 20,
                    alignItems: "center",
                    marginBottom: 10,
                  }}
                >
                  {/* <Text style={{ fontSize: 19, fontWeight: "bold" }}>填写问卷</Text> */}
                  <View style={{ flexDirection: "row", marginTop: 10 }}>
                    <Text style={{ marginTop: 5, fontWeight: "bold" }}>
                      问卷编码：
                    </Text>
                    <TextInput
                      style={{
                        width: "55%",
                        borderColor: "#ddd",
                        borderBottomWidth: 1,
                        borderRadius: 3,
                        paddingLeft: 7,
                        paddingRight: 7,
                        textAlign: "center",
                        marginLeft: 5,
                        marginRight: 5,
                      }}
                      multiline={true}
                      // maxLength={500}
                      value={title}
                      placeholder={"问卷编码"}
                      editable={isEdit}
                      onChangeText={(text) => {
                        setTitle(text);
                      }}
                    ></TextInput>
                  </View>
                </View>
                {QuesBody.map((content, index1) => {
                  // setShowOption();
                  if (content.visible == true) {
                    return (
                      <View key={index1}>
                        <TouchableOpacity
                          onPress={() => {
                            setVisibleArr((preArr) => {
                              return preArr.map((item, t_index) => {
                                return t_index == index1 ? !item : item;
                              });
                            });
                            // console.log(visibleArr);
                          }}
                        >
                          <View
                            style={{
                              height: 15,
                              backgroundColor: "#eee",
                              marginTop: 15,
                              marginBottom: 7,
                            }}
                          ></View>
                          <View
                            style={{
                              marginTop: 10,
                              alignItems: "center",
                              marginBottom: 10,
                            }}
                          >
                            <Text style={{ fontSize: 16, fontWeight: "bold" }}>
                              {String.fromCharCode(index1 + 65) +
                                "  " +
                                content.head}
                            </Text>
                          </View>
                        </TouchableOpacity>

                        {visibleArr[index1] ? (
                          <View>
                            {content.contents.map((question, index) => {
                              if (
                                (question.type == 1 || question.type == 7) &&
                                question.visible == true
                              ) {
                                return (
                                  <View key={index}>
                                    <View
                                      style={{
                                        height: 5,
                                        backgroundColor: "#f8f8f8",
                                      }}
                                    ></View>
                                    <ShowEssayQues
                                      isEdit={isEdit}
                                      flag={[index1, index, -1]}
                                      editAnswer={editAnswer}
                                      number={
                                        String.fromCharCode(index1 + 65) +
                                        (index + 1)
                                      }
                                      QuesContent={question}
                                    ></ShowEssayQues>
                                  </View>
                                );
                              } else if (
                                (question.type == 2 || question.type == 3) &&
                                question.visible == true
                              ) {
                                return (
                                  <View key={index}>
                                    <View
                                      style={{
                                        height: 5,
                                        backgroundColor: "#f8f8f8",
                                      }}
                                    ></View>
                                    <ShowChoiceQues
                                      isEdit={isEdit}
                                      flag={[index1, index, -1]}
                                      editAnswer={editAnswer}
                                      number={
                                        String.fromCharCode(index1 + 65) +
                                        (index + 1)
                                      }
                                      QuesContent={question}
                                    ></ShowChoiceQues>
                                  </View>
                                );
                              } else if (
                                question.type == 4 &&
                                question.visible == true
                              ) {
                                return (
                                  <View key={index}>
                                    <View
                                      style={{
                                        height: 5,
                                        backgroundColor: "#f8f8f8",
                                      }}
                                    ></View>
                                    <ShowCompletion
                                      isEdit={isEdit}
                                      flag={[index1, index, -1]}
                                      editAnswer={editAnswer}
                                      number={
                                        String.fromCharCode(index1 + 65) +
                                        (index + 1)
                                      }
                                      QuesContent={question}
                                    ></ShowCompletion>
                                  </View>
                                );
                              } else if (
                                question.type == 5 &&
                                question.visible == true
                              ) {
                                return (
                                  <View key={index}>
                                    <View
                                      style={{
                                        height: 5,
                                        backgroundColor: "#f8f8f8",
                                      }}
                                    ></View>
                                    <ShowComplexQues
                                      isEdit={isEdit}
                                      flag={[index1, index]}
                                      editAnswer={editAnswer}
                                      number={
                                        String.fromCharCode(index1 + 65) +
                                        (index + 1)
                                      }
                                      QuesContent={question}
                                    ></ShowComplexQues>
                                  </View>
                                );
                              }
                            })}
                          </View>
                        ) : null}
                      </View>
                    );
                  }
                })}
              </View>
            </ScrollView>
          )}

          {btnType == 1 ? (
            <View style={styles.btnBox}>
              <TouchableOpacity
                style={styles.backBtn}
                onPress={() => {
                  navigation.goBack();
                }}
              >
                <Text style={{ color: "#41C3EE" }}>返回</Text>
              </TouchableOpacity>
              {!isAddTag ? (
                <TouchableOpacity
                  style={[styles.backBtn, { marginLeft: "5%" }]}
                  onPress={async () => {
                    if (haveSave) {
                      setIsVisible(true);
                      setIsExamining(true);
                      let isSuccess = true;
                      await editAndJudgeMyQues(quesIndex, (value) => {
                        isSuccess = value;
                      });
                      setIsExamining(false);
                    } else {
                      Alert.alert("请先暂存这份问卷！");
                    }
                  }}
                >
                  <Text style={{ color: "#41C3EE" }}>保存</Text>
                </TouchableOpacity>
              ) : null}
              {!isAddTag ? (
                <TouchableOpacity
                  style={[styles.backBtn, { marginLeft: "5%" }]}
                  onPress={async () => {
                    if (haveSave) {
                      setIsVisible(true);
                      setIsExamining(true);
                      let isSuccess = false;
                      await postMyQues(quesIndex, (value) => {
                        isSuccess = value;
                      });
                      setIsExamining(false);
                      if (isSuccess) {
                        navigation.goBack();
                      }
                    } else {
                      Alert.alert("请先暂存这份问卷！");
                    }
                  }}
                >
                  <Text style={{ color: "#41C3EE" }}>上传</Text>
                </TouchableOpacity>
              ) : null}

              <TouchableOpacity
                style={styles.submitBtn}
                onPress={async () => {
                  setIsSaving(true);
                  // addQues({ type: 0, head: groupTitle, contents: quesArr });
                  // updateAnswer(QuesBody);
                  let t_data = {
                    ...UserQuesData,
                    title: title,
                    body: QuesBody,
                  };
                  // console.log("保存的数据---", t_data);
                  let isSuccess = true;
                  if (isAddTag) {
                    await addNewQues(t_data, (value) => {
                      isSuccess = value;
                    });
                    setIsAddTag(false);
                  } else {
                    const user_id = store.getState().authR.user;
                    console.log("用户---", MyQuesData[quesIndex].title);
                    t_data = {
                      ...t_data,
                      _id: MyQuesData[quesIndex]._id,
                      filedata: MyQuesData[quesIndex].filedata._id,
                      userproblem: MyQuesData[quesIndex].userproblem._id,
                      opinions: MyQuesData[quesIndex].opinions._id,
                      // user: user_id,
                    };
                    await editMyQues(quesIndex, t_data, (value) => {
                      isSuccess = value;
                    });
                  }
                  if (isSuccess) {
                    setHaveSave(true);
                  }
                  setIsSaving(false);
                }}
              >
                <Text style={{ color: "#fff" }}>暂存</Text>
              </TouchableOpacity>
            </View>
          ) : null}
          {btnType == 2 ? (
            <View style={styles.btnBox}>
              <TouchableOpacity
                style={styles.backBtn}
                onPress={() => {
                  handleExamine(quesIndex, 3);
                }}
              >
                <Text style={{ color: "#41C3EE" }}>驳回</Text>
              </TouchableOpacity>

              <TouchableOpacity
                style={styles.submitBtn}
                onPress={() => {
                  handleExamine(quesIndex, 2);
                }}
              >
                <Text style={{ color: "#fff" }}>通过</Text>
              </TouchableOpacity>
            </View>
          ) : null}
        </View>
      )}
      {useQuesLoading == "error" ? <Error></Error> : null}
      <Modal animationType="fade" transparent={true} visible={isSaving}>
        <Loading text="保存中"></Loading>
      </Modal>
      <Modal animationType="fade" transparent={true} visible={isExamining}>
        <Loading text="处理中"></Loading>
      </Modal>
      <Modal
        animationType="fade"
        // transparent={true}
        visible={errorAlter != "" && isVisible}
      >
        <View style={styles.ModalBackground}></View>
        <TouchableWithoutFeedback
          onPress={() => {
            setIsVisible(false);
          }}
        >
          <View style={styles.ModalTop}>
            <View style={{ height: "95%", justifyContent: "center" }}>
              <View>
                <Text style={{ marginLeft: 20, marginRight: 20 }}>
                  请先完成以下题目:
                </Text>
                <Text style={{ marginLeft: 20, marginRight: 20 }}>
                  {errorAlter}
                </Text>
              </View>
            </View>

            <View
              style={{
                marginBottom: 20,
                alignItems: "center",
              }}
            >
              <Text style={{ color: "#aaa" }}>点击空白区域退出</Text>
            </View>
          </View>
        </TouchableWithoutFeedback>
      </Modal>
      <Modal
        animationType="fade"
        // transparent={true}
        visible={conditionAlter != "" && isVisible}
      >
        <View style={styles.ModalBackground}></View>
        <TouchableWithoutFeedback
          onPress={() => {
            setIsVisible(false);
          }}
        >
          <View style={styles.ModalTop}>
            <View style={{ height: "95%" }}>
              <Text style={{ marginLeft: 20, marginRight: 20, marginTop: 100 }}>
                您的问卷内容不满足以下条件:
              </Text>
              <Text style={{ marginLeft: 20, marginRight: 20 }}>
                {conditionAlter}
              </Text>
              <View style={{ height: 100 }}></View>
            </View>

            <View
              style={{
                marginBottom: 20,
                alignItems: "center",
              }}
            >
              <Text style={{ color: "#aaa" }}>点击空白区域退出</Text>
            </View>
          </View>
        </TouchableWithoutFeedback>
      </Modal>
    </View>
  );
};

var styles = StyleSheet.create({
  container: {
    // marginTop: Platform.OS === "android" ? StatusBar.currentHeight : 0,
    height: "100%",
    backgroundColor: "white",
    // alignItems: "center",
    // justifyContent: "center",
    // backgroundColor: "#eee",
  },
  optionBtn: {
    height: 40,
    width: 250,
    marginTop: 15,
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: "#41C3EE",
    elevation: 4, //设置阴影角度，通过这个设置有无阴影
    shadowOffset: {
      // 设置阴影偏移量
      width: 0,
      height: 0,
    },
    shadowRadius: 4, // 设置阴影模糊半径
    shadowOpacity: 0.5, // 设置阴影的不透明度
    shadowColor: "gray", // 设置阴影色
  },
  ModalBackground: {
    backgroundColor: "#727272",
    opacity: 0.3,
    zIndex: 0,
    position: "absolute",
    width: "100%",
    height: "100%",
  },
  ModalStyle: {
    borderTopLeftRadius: 10,
    borderTopRightRadius: 10,
    backgroundColor: "#ffffff",
    zIndex: 1,
    position: "relative",
  },
  ModalTop: {
    flex: 1,
  },
  modalOption: {
    // backgroundColor: "yellow",
    width: "100%",
    padding: 15,
    borderBottomWidth: 0.5,
    borderBottomColor: "#e6e6e6",
  },
  modalText: {
    alignSelf: "center",
    fontSize: 16,
    color: "#201D1D",
  },
  backBtn: {
    flex: 3.7,
    borderWidth: 1,
    borderColor: "#41C3EE",
    // alignContent: "center",
    // justifyContent: "center",
    alignItems: "center",
    padding: 10,
    borderRadius: 5,
  },
  submitBtn: {
    flex: 5.7,
    marginLeft: "5%",
    backgroundColor: "#41C3EE",
    alignItems: "center",
    padding: 10,
    borderRadius: 5,
  },
  btnBox: {
    flexDirection: "row",
    marginLeft: "5%",
    marginRight: "5%",
    marginTop: 10,
    marginBottom: 10,
  },
  alterView: {
    height: "100%",
    alignItems: "center",
    justifyContent: "center",
  },
  ModalBackground: {
    backgroundColor: "#727272",
    opacity: 0.3,
    zIndex: 0,
    position: "absolute",
    width: "100%",
    height: "100%",
  },
  ModalStyle: {
    borderTopLeftRadius: 10,
    borderTopRightRadius: 10,
    backgroundColor: "#ffffff",
    zIndex: 1,
    position: "relative",
  },
  ModalTop: {
    flex: 1,
  },
});

export default CompleteQues;
